<@override name="content">
<div class="layui-fluid">
    <div class="layui-row layui-col-space15" id="app">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">搜索条件</div>
                <div class="layui-card-body">
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">评论状态</label>
                                <div class="layui-input-block">
                                    <select name="isReply">
                                        <option value="">是否回复</option>
                                        <option value="1">已回复</option>
                                        <option value="0">未回复</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">用户名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="userName" class="layui-input" placeholder="请输入用户名称">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">商品名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="goodsName" class="layui-input" placeholder="请输入商品名称">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="search"
                                            lay-filter="search">
                                        <i class="layui-icon layui-icon-search"></i>搜索
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <!--产品列表-->
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="alert alert-info" role="alert">
                    列表[排序]可进行快速修改,双击或者单击进入编辑模式,失去焦点可进行自动保存
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                </div>
                <div class="layui-card-header">评论列表</div>
                <div class="layui-card-body">
                    <div class="layui-btn-container">
                        <button type="button" class="layui-btn layui-btn-sm"
                                onclick="$eb.createModalFrame(this.innerText,'/admin/comment/add')">添加虚拟评论
                        </button>
                        <button class="layui-btn layui-btn-sm" onclick="batchReply()">批量回复</button>
                    </div>
                    <table class="layui-hide" id="List" lay-filter="List"></table>
                    <script type="text/html" id="pic">
                        {{# if(d.pic){ }}
                        <img style="cursor: pointer" lay-event='open_image' src="{{d.pic}}">
                        {{# }else{ }}
                        暂无图片
                        {{# } }}
                    </script>
                    <!--商品信息-->
                    <script type="text/html" id="info">
                        <div>
                            <span>
                                <img style="width: 30px;height: 30px;margin:0;cursor: pointer;"
                                     src="{{d.goodsImage}}">
                            </span>
                            <span>{{d.goodsName}}</span>
                        </div>
                    </script>
                    <script type="text/html" id="act">
                        <button class="layui-btn btn-danger layui-btn-xs" lay-event='top'>
                            <i class="fa fa-arrows-v"></i> 置顶
                        </button>
                        <button type="button" class="layui-btn layui-btn-xs" onclick="dropdown(this)">操作 <span
                                class="caret"></span></button>
                        <ul class="layui-nav-child layui-anim layui-anim-upbit">
                            <li>
                                <a href="javascript:void(0);"
                                   onclick="$eb.createModalFrame('修改评论','${request.contextPath}/admin/comment/add?id={{d.id}}')">
                                    <i class="fa fa-edit"></i> 修改评论
                                </a>
                            </li>
                            <li>
                                <a href="javascript:void(0);" lay-event='delstor'>
                                    <i class="fa fa-trash"></i> 删除
                                </a>
                            </li>
                        </ul>

                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="${request.contextPath}/js/layuiList.js"></script>
</@override>
<@override name="script">
<script>
    setTimeout(function () {
        $('.alert-info').hide();
    },3000);
    //实例化form
    layList.form.render();
    //加载列表
    layList.tableList('List',"${request.contextPath}/admin/comment/listData",function (){
        return [
            {type: 'checkbox'},
            {field: 'id', title: 'ID', sort: true,event:'id',width:'4%',align:'center'},
            {field: 'info', title: '商品信息', templet: "#info", height: 'full-20'},
            {field: 'userName', title: '用户名称',align:'center'},
            {field: 'star1', title: '商品质量',align:'center'},
            {field: 'star2', title: '服务态度',align:'center',width:'8%'},
            {field: 'comment', title: '评价内容',width:'10%',align:'center'},
            {field: 'reply', title: '回复内容',align:'center'},
            {field: 'sort', title: '排序',width:'8%',edit:'sort',align:'center'},
            {field: 'right', title: '操作',align:'center',toolbar:'#act',width:'12%',align:'center'}
        ];
    });
    //自定义方法
    var action= {
        set_category: function (field, id, value) {
            var url = '${request.contextPath}/admin/comment/updateSort/'+value+'/'+id;
            layList.basePost(url,function (res) {
                layList.msg(res.msg);
            });
        },
    }
    function batchReply(){
        var ids = layList.getCheckData().getIds('id');
        if (ids.length) {
            $eb.createModalFrame('批量回复','/admin/comment/reply?id='+ids.join(","))
        } else {
            layList.msg('请选择要回复的评论');
        }
    }
    //查询
    layList.search('search',function(where){
        layList.reload(where);
    });
    layList.switch('is_show',function (odj,value) {
        var url = "${request.contextPath}/admin/goodsType/setShow/";
        if(odj.elem.checked==true){
            url = url + value + "/1";
            layList.basePost(url,function (res) {
                layList.msg(res.msg);
            });
        }else{
            url = url + value + "/0";
            layList.basePost(url,function (res) {
                layList.msg(res.msg);
            });
        }
    });
    //快速编辑
    layList.edit(function (obj) {
        var id=obj.data.id,value=obj.value;
        switch (obj.field) {
            case 'sort':
                action.set_category('sort',id,value);
                break;
        }
    });
    //监听并执行排序
    layList.sort(['id','sort'],true);
    //点击事件绑定
    layList.tool(function (event,data,obj) {
        switch (event) {
            case 'delstor':
                var url = "${request.contextPath}/admin/comment/delete?id="+data.id;
                $eb.$swal('delete',function(){
                    $eb.axios.post(url).then(function(res){
                        if(res.status == 200 && res.data.code == 200) {
                            $eb.$swal('success',res.data.msg);
                            obj.del();
                        }else
                            return Promise.reject(res.data.msg || '删除失败')
                    }).catch(function(err){
                        $eb.$swal('error',err);
                    });
                })
                break;
              case 'top':
                var url = "${request.contextPath}/admin/comment/topSort/"+data.id;
                $eb.axios.post(url).then(function(res){
                        if(res.status == 200 && res.data.code == 200) {
                            $eb.$swal('success',res.data.msg);
                             location.reload();
                        }else
                            return Promise.reject(res.data.msg || '置顶失败')
                    }).catch(function(err){
                        $eb.$swal('error',err);
                    });
                break;
            case 'open_image':
                $eb.openImage(data.pic);
                break;
        }
    })
    function dropdown(that) {
        var oEvent = arguments.callee.caller.arguments[0] || event;
        oEvent.stopPropagation();
        var offset = $(that).offset();
        var top = offset.top - $(window).scrollTop();
        var index = $(that).parents('tr').data('index');
        $('.layui-nav-child').each(function (key) {
            if (key != index) {
                $(this).hide();
            }
        })
        if ($(document).height() < top + $(that).next('ul').height()) {
            $(that).next('ul').css({
                'padding': 10,
                'top': -($(that).parents('td').height() / 2 + $(that).height() + $(that).next('ul').height() / 2),
                'min-width': 'inherit',
                'position': 'absolute'
            }).toggle();
        } else {
            $(that).next('ul').css({
                'padding': 10,
                'top': $(that).parents('td').height() / 2 + $(that).height(),
                'min-width': 'inherit',
                'position': 'absolute'
            }).toggle();
        }
    }


</script>
</@override>
<@extends name="../../public/container.html"/>